package com.fancy.learncenter.ui.adapter;

import android.content.Context;
import android.text.TextUtils;
import android.view.View;
import android.widget.FrameLayout;
import android.widget.ImageView;
import android.widget.TextView;

import com.fancy.learncenter.R;
import com.fancy.learncenter.bean.CartoonTextsBean;
import com.fancy.learncenter.common.JumpIntentKey;
import com.fancy.learncenter.ui.adapter.base.CommonRecycleViewAdapter;
import com.fancy.learncenter.ui.adapter.base.CustomViewHold;
import com.fancy.learncenter.ui.callback.AlbumImpl;

import java.util.List;

/**
 * Created by shiweiwei on 2018/1/4.
 */

public class CartoonQuestionTextOptionAdapter extends CommonRecycleViewAdapter<CartoonTextsBean> {

    JumpIntentKey.QUESTION_ENTER_TYPE type;
    List<CartoonTextsBean> itemDatas;


    public void setListener(AlbumImpl listener) {
        this.listener = listener;
    }

    private AlbumImpl listener;

    public CartoonQuestionTextOptionAdapter(Context mContext, JumpIntentKey.QUESTION_ENTER_TYPE type, List<CartoonTextsBean> itemDatas) {
        super(mContext, R.layout.cartoon_question_option_text_item, itemDatas);
        this.type = type;
        this.itemDatas = itemDatas;
    }

    @Override
    public void bindView(CustomViewHold customViewHold, final CartoonTextsBean item, final int position) {

        TextView option_text = customViewHold.getView(R.id.option_text);
        FrameLayout frameBg = customViewHold.getView(R.id.frame_bg);

        if (!TextUtils.isEmpty(item.getValue())) {
            option_text.setText(item.getValue());
        }


        switch (type) {

            case DO_WORK:
            case CONTINUE_WORK:
            case DO_IT_AGAIN:
            case HAS_CORRECTED:
            case NOT_CORRECTED:
            case ERROR_KINDS:
                customViewHold.getRoorView().setEnabled(true);
                break;
            case WORK_REPORT:
            case NO_CLICK:
            case TEACHER_WORK_PREVIEW:
                customViewHold.getRoorView().setEnabled(false);
                break;
        }

        if (item.getStatus() == null) {  //设置默认值
            item.setStatus(JumpIntentKey.OPTION_STATUS.STATUS_DEFAULT);
        }

        switch (item.getStatus()) {
            case STATUS_DEFAULT:
                switch (type) {
                    case TEACHER_WORK_PREVIEW:
                        frameBg.setBackgroundResource(R.mipmap.quetion_option_text);
                        break;
                    default:
                        frameBg.setBackgroundResource(R.mipmap.quetion_option_text);
                        break;
                }

                break;
            case STATUS_CHOOSE:
                frameBg.setBackgroundResource(R.mipmap.question_option_text_selected);
                break;
            case STATUS_WRONG:
                frameBg.setBackgroundResource(R.mipmap.cartoon_sentence_wrong);

                break;
            case STATUS_RIGHT:
                switch (type) {
                    case TEACHER_WORK_PREVIEW:
                        frameBg.setBackgroundResource(R.drawable.teacher_work_preview_option_right_item);
                        break;
                    default:
                        frameBg.setBackgroundResource(R.mipmap.cartoon_sentence_right);
                        break;
                }
                break;
        }

        customViewHold.getRoorView().setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {

                if (listener != null) {
                    listener.onClick(position);
                }


            }
        });


    }
}
